package com.europe.business.europebusiness.ui.activity.base;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.europe.business.europebusiness.R;
import com.europe.business.europebusiness.ui.activity.LoginActivity;
import com.europe.business.europebusiness.ui.utils.LanguageUtil;

import java.util.Map;

public abstract class BaseActivity extends AppCompatActivity {
    private ProgressDialog dialog;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(setLayout());
        initView();
        initData();

    }

    @Override
    protected void onResume() {
        super.onResume();
        LanguageUtil.isLanguageChanged(this, LoginActivity.class);
    }


    /**
     * 设置子界面布局
     *
     * @return
     */
    protected abstract int setLayout();

    protected abstract void initView();

    protected void initData() {

    }

    ;

    /**
     * 显示短时间的toast
     *
     * @param toast
     */
    protected void showToastShort(String toast) {
        Toast.makeText(this, toast, Toast.LENGTH_SHORT).show();
    }

    /**
     * 显示长时间的toast
     *
     * @param toast
     */

    protected void showToastLong(String toast) {
        Toast.makeText(this, toast, Toast.LENGTH_LONG).show();
    }

    protected void showProgressDialog() {
        showProgressDialog(getString(R.string.info_loading));
    }

    protected void showProgressDialog(String msg) {
        if (null == dialog) {
            dialog = new ProgressDialog(this);
            dialog.setMessage(msg);
        }
        dialog.show();
    }

    protected void dismissProgressDialog() {
        if (null != dialog) {
            dialog.dismiss();
        }
    }

    /**
     * activity的跳转(带Intent)
     *
     * @param intent
     */
    protected void startAct(Intent intent) {

        startActivity(intent);
    }


    /**
     * activity的跳转(不带数据)
     *
     * @param cls
     */
    protected void startAct(Class cls) {
        Intent intent = new Intent();
        intent.setClass(this, cls);
        startActivity(intent);
    }

    /**
     * activity的跳转(带数据)
     */
    protected void startAct(Class cls, Map map) {
//        Intent intent = new Intent();
//        Set set = map.keySet();
//        while(set.iterator().hasNext()){
//            String key = set.iterator().next().toString();
//            Object object = map.get(key);
//            intent.putExtra(key, object);
//        }
//
//        startActivity(intent);
    }


    /**
     * activity的跳转(带包裹数据bundle)
     *
     * @param cls
     * @param data
     */
    protected void startAct(Class cls, Bundle data) {
        Intent intent = new Intent();
        intent.putExtras(data);
        intent.setClass(this, cls);
        startActivity(intent);
    }


}
